package de.mahosoftware.gwt.games.durak.client.module;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import de.mahosoftware.gwt.games.durak.logic.Rules;

public class Player extends Rules{

	private String name;
	protected List<Card> hand = new ArrayList<Card>();

	public Player(String name) {
		setName(name);
		setStatus(Status.neutral);
	}

	private void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public List<Card> getHand() {
		return hand;
	}

	public Card giveCard(int cardIndex) {
		Card card = hand.get(cardIndex);
		hand.remove(cardIndex);
		return card;
	}

	public Card giveCard(Card card) {
		return giveCard(hand.indexOf(card));
	}

	public boolean getCard(Card card) {
		if (hand.contains(card)) {
			return false;
		} else {
			hand.add(card);
			return true;
		}
	}

	public void printCards() {
		for (Card c : hand) {
			c.printInfo();
		}
	}

	public void sortCards() {
		Collections.sort(hand);
//		List<Card> temp = new ArrayList<Card>();
//		for (Color c : Color.values()) {
//			for (Card cd : hand) {
//				if (cd.getColor() == c) {
//					temp.add(cd);
//				}
//			}
//		}
//		
//		hand = temp;
	}

}
